<?php

require_once './include/common.inc.php';
checkLogin();
$postiondiv='<div class="position"><a href="index.php">Home</a> &gt; <span class="position">View Wishlist Details</span></div>';
$baner_img='<div class="bigtitle">Wishlist Details</div>';

$page_title = 'jans2en furniture - Wish List - Wish List Product Listing';
getMyParam('pid');
getMyParam('wid');
getMyParam('act');

if (!is_numeric($wid) || $wid<=0) {
    header("Location:wishlist_view.php");
    exit;
}

if ($act == "delone" && is_numeric($pid) && $pid>0) {
    $sql = "SELECT `id`, `product_list` FROM `wishlist` WHERE `id`= $wid AND `user_id` = $jansen_uid";
    $tmp = $db->get_one($sql);
    $tmp_ary = explode("|", $tmp['product_list']);
    $new_ary = array();
    foreach ($tmp_ary as $v) {
        if ($v != $pid) {
            $new_ary[] = $v;
        }
    }
    
    $total_wishlist_qty = empty($new_ary) ? 0 : count($new_ary);
    //echo $total_wishlist_qty;exit;
    setcookie('jansen_wishlist_qty', $total_wishlist_qty, time()+3600*24*365, "/");

    $new_product_list_str = @implode("|", $new_ary);
    $sql = "UPDATE `wishlist` SET `product_list`= '$new_product_list_str' WHERE `id`= $wid AND `user_id` = $jansen_uid";
    $db->query($sql);
    header("Location:wishlist_details_view.php?wid=" . $wid);
}

$sql = "SELECT `id`, `product_list`, `date` FROM `wishlist` WHERE `id`= $wid AND `user_id` = $jansen_uid";
$wishlist_ary = $db->get_one($sql);

$product_ary = array();

$new_product_list_str = @str_replace("|", ",", $wishlist_ary['product_list']);

// *** page code start ***
$page_url = 'wishlist_details_view.php?wid=' . $wid . '&';
//$sql_all_num = count(explode("|", $wishlist_ary['product_list']));

$sql = "SELECT count(`id`) as num FROM `product` WHERE `id` IN (" . $new_product_list_str . ")";
$tmp_ary1 = $db->get_one($sql);
$sql_all_num = $tmp_ary1['num'];   

$ppp = 10;
getMyParam('page');
$page = empty($page) || !ispage($page) ? 1 : $page;
$start_limit = ($page - 1) * $ppp;
if($start_limit > $sql_all_num) {
    $start_limit = 0;
    $page = 1;
}

$page_show = getPhotoPageStr($sql_all_num, $page, $ppp, $page_url);
// *** page code end ***

if (!empty($wishlist_ary['product_list'])) {
    /*
    $tmp_product_list_ary = explode("|", $wishlist_ary['product_list']);
    $new_product_list_str = implode(",", $tmp_product_list_ary);
    */
    
    $sql = "SELECT * FROM `product` WHERE `id` IN (" . $new_product_list_str . ") LIMIT $start_limit, $ppp";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $product_ary[$rs['id']] = $rs;
    }
}

//echo "<pre>";print_r($product_ary);exit();

require_once PrintEot('header');
require_once PrintEot('wishlist_details_view');
require_once PrintEot('footer');

?>